package sqp.demo.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import sqp.demo.dao.StudentRepository;
import sqp.demo.model.Student;

import java.util.List;


/**
 * Created by SunQiPeng on 2016/11/14.
 */
@Service
public class StudService {
    @Autowired
    private StudentRepository studentRepository;

    @Transactional(propagation = Propagation.REQUIRED)
    public void save(Student student){
        studentRepository.save(student);
//        int i = 1/0;
    }

    public List<Student> findAll(){
        return (List<Student>) studentRepository.findAll();
    }

    public Student findOne(long id){
        return studentRepository.findOne(id);
    }

    public void testImpl(){
        studentRepository.sayHello();
    }
}
